<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增合作伙伴')" />
    <style>
        .m{
            position: relative;
            top:150px
        }
    </style>

</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="registerDeptForm">
            <div class="form-group">
                <label class="col-sm-6 control-label">
                    <h1>注册成为合作伙伴</h1>
                </label>

            </div>
            <div class="form-group hidden">
                <label class="col-sm-4 control-label">上级id：</label>
                <div class="col-sm-4">
                    <input name="parentId" th:value="100" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label is-required">企业名称：</label>
                <div class="col-sm-4">
                    <input name="deptName" id="deptName" placeholder="请输入企业名称" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label is-required">企业税号：</label>
                <div class="col-sm-4">
                    <input name="code" id="code" class="form-control" placeholder="请输入企业税号" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label is-required">登录账号：</label>
                <div class="col-sm-4">
                    <input name="loginName" id="loginName" placeholder="请输入登录账号" class="form-control"  type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label is-required">登录密码：</label>
                <div class="col-sm-4">
                    <input name="password" id="password" th:type="password" placeholder="请输入登录密码" class="form-control"  type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label is-required">企业负责人：</label>
                <div class="col-sm-4">
                    <input name="leader" class="form-control" placeholder="请输入企业负责人"  type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label is-required">联系电话(手机)：</label>
                <div class="col-sm-4">
                    <input name="phone" class="form-control" placeholder="请输入联系电话(手机)"  type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label is-required">企业地址：</label>
                <div class="col-sm-4">
                    <input name="address" class="form-control" placeholder="请输入企业地址"  type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label"></label>
                <div class="col-sm-4">
                   <div style="display: flex;justify-content: space-around ">
                       <button class="btn btn-default">返回</button>
                       <button class="btn btn-success"  data-loading="正在验证注册，请稍候...">保存</button>
                   </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
<!--    <script th:src="@{/js/register.js?v=1.5}"></script>-->
<script>
    $("#registerDeptForm").validate({
        onkeyup: false,
        rules:{
            deptName:{
                remote: {
                    url: ctx + "partner/dept/checkDeptUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "deptName" : function() {
                            return $.common.trim($("#deptName").val());
                        }
                    }
                }
            },
            code:{
                remote: {
                    url: ctx + "partner/dept/checkDeptUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "code" : function() {
                            return $.common.trim($("#code").val());
                        }
                    }
                }
            },
            loginName:{
                remote: {
                    url: ctx + "system/user/checkLoginNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "loginName" : function() {
                            return $.common.trim($("#loginName").val());
                        }
                    }
                }
            },
            phone:{
                remote: {
                    minlength: 11,
                    maxlength: 11,
                    url: ctx + "system/user/checkPhoneUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "phone" : function() {
                            return $.common.trim($("#phone").val());
                        }
                    }
                }
            },
            password:{
                minlength: 6,
                maxlength: 20
            },
            focusCleanup: true
        },
        messages: {
            "deptName": {
                remote: "企业名称已经存在"
            },
            "code": {
                remote: "企业税号已经存在"
            },
            "loginName": {
                remote: "用户已经存在"
            },
            "phone":{
                remote: "手机号码已经存在"
            }

        },
        submitHandler:function (form){
            register();
        },
        focusCleanup: true
    })




    function register() {
        $.modal.loading($("#btnSubmit").data("loading"));
        $.ajax({
            type: "post",
            url: ctx + "partner/dept/register",
            data: $('#registerDeptForm').serialize(),
            success: function(r) {
                debugger;
                if (r.code == web_status.SUCCESS) {
                    layer.alert("<font color='red'>恭喜你，您的账号【 " +$("#deptName").val()+ " 】注册成功！</font>", {
                            icon: 1,
                            title: "系统提示"
                        },
                        function(index) {
                            //关闭弹窗
                            layer.close(index);
                            location.href = ctx + 'login';
                        });
                } else {
                    $.modal.closeLoading();
                    $.modal.msg(r.msg);
                }
            }
        });
    }

</script>

</body>
</html>
